`timescale 1ns / 1ps

module GRF(
    input clk,
    input reset,
    input en,
    input [4:0] A1,
    input [4:0] A2,
    input [4:0] A3,
    output [31:0] V1,
    output [31:0] V2,
    input [31:0] Rin,
    input [31:0] addr
    );

    reg [31:0] word[0:31];

    initial begin: init
        integer i;
        for(i = 0; i < 32; i = i + 1)
            word[i] = 0;
    end

    assign V1 = (en && A3 && A3 == A1)? Rin : word[A1];
    assign V2 = (en && A3 && A3 == A2)? Rin : word[A2];

    always @(posedge clk)  begin: alw
        if(reset) begin: res
            integer i;
            for(i = 0; i < 32; i = i + 1)
                word[i] = 0;
        end
        else if(en && A3) begin
            $display("%d@%h: $%d <= %h", $time, addr, A3, Rin);
            word[A3] = Rin;
        end
    end

endmodule
